package com.hqd.ch03.v34.context.validation;

import com.hqd.ch03.v34.beans.TypeConverter;
import com.hqd.ch03.v34.beans.property.PropertyEditorRegistry;
import com.hqd.ch03.v34.beans.property.support.SimpleTypeConverter;

import java.beans.PropertyEditor;

public class DataBinder implements PropertyEditorRegistry, TypeConverter {
    private Object target;

    private String objectName;
    private SimpleTypeConverter typeConverter;

    @Override
    public <T> Object convertIfNecessary(Object value, Class<T> requiredType) {
        return getTypeConverter().convertIfNecessary(value, requiredType);
    }

    @Override
    public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) {

    }

    @Override
    public PropertyEditor findCustomEditor(Class<?> requiredType) {
        return null;
    }

    protected TypeConverter getTypeConverter() {
        return getSimpleTypeConverter();
    }


    private TypeConverter getSimpleTypeConverter() {
        return this.typeConverter;
    }

    public Object getTarget() {
        return target;
    }
}
